package com.atguigu.gmall.user.service.impl;

import com.atguigu.gmall.model.user.UserInfo;
import com.atguigu.gmall.user.mapper.UserInfoMapper;
import com.atguigu.gmall.user.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

/**
 * 用户管理
 */

@Service
public class UserServiceImpl implements UserService {


    @Autowired
    private UserInfoMapper userInfoMapper;

    //判断用户名密码是否正确
    @Override
    public UserInfo login(UserInfo userInfo) {

        //MD5 Hex 十六进制加密
        userInfo.setPasswd(DigestUtils.md5DigestAsHex(userInfo.getPasswd().getBytes()));
        //根据用户名 及加密后的密码 查询用户信息  查询出来之后不是NULL
        UserInfo userInfo1 = userInfoMapper.selectOne(new QueryWrapper<UserInfo>()
                .eq("login_name", userInfo.getLoginName())
                .eq("passwd", userInfo.getPasswd()));
        return userInfo1;
    }

    public static void main(String[] args) {
        String s = DigestUtils.md5DigestAsHex("123".getBytes());
        System.out.println(s);
    }
}
